package com.example.springtransactional.service;

import com.example.springtransactional.dao.InsertDataDao;
import com.example.springtransactional.domain.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @auther:lgb
 * @Date: 2021/4/24
 */
@Service
public class TestBService {
    @Resource
    InsertDataDao insertDataDao;
    @Resource
    TestAService testAService;

    @Transactional(rollbackFor = {Exception.class}, timeout = 1, propagation = Propagation.REQUIRED)
    public void methodB() {
        System.out.println("dosomethingA");
        testAService.methodA();
        System.out.println("dosomethingB");
        try {
            Thread.sleep(1600);
            insertDataDao.insertData(new User(3, "methodB", 10));

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
